import 'package:flutter/material.dart';
import '../public/publicMethods.dart';

import 'package:flutter/services.dart';
const methodChannel = const MethodChannel('samples.flutter.dev/test');

class User extends StatelessWidget {
  const User({super.key});

  @override
  Widget build(BuildContext context) {
    return _User();
  }
}

class _User extends StatefulWidget {


  @override
  _UserState createState() => new _UserState();
}


/// RestorationProperty objects can be used because of RestorationMixin.
class _UserState extends State<_User>{
  double getStatusBarHeight() {
    return MediaQuery.of(context).padding.top;
  }

  double rem = 0;
  @override
  Widget build(BuildContext context) {

    print(UserData);
    rem =  MediaQuery.of(context).size.width/1080;
    return Scaffold(
      body: Container(

          child: Container(
            width: 990*rem,
            height:MediaQuery.of(context).size.height,
            margin: EdgeInsets.fromLTRB(0, getStatusBarHeight(), 0, 0),
            child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    width: 990*rem,
                    padding: EdgeInsets.all(30*rem),
                    child: Hero(tag: 'title', child: Text(UserData['nickname'],style: TextStyle(color:Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal, fontSize: 100*rem),),
                    ),),


                  Container(
                    padding: EdgeInsets.all(30*rem),
                    child: Container(
                      height: 127*rem,
                      child: ElevatedButton(
                        style:ButtonStyle(
                            backgroundColor:MaterialStateProperty.all(Color.fromRGBO(11, 135, 255, 1)),
                            foregroundColor: MaterialStateProperty.all(Colors.white),
                            shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8*rem))),
                            side:MaterialStateProperty.all(BorderSide(
                                width:3*rem,color:Color.fromRGBO(11, 135, 255, 1)
                            ))
                        ),
                        child: Text('退出登陆',
                            style:TextStyle(
                              fontSize:40*rem,
                            )
                        ),
                        onPressed: () async{
                          final String token =  await methodChannel.invokeMethod('getSharedPreferences','token');
                          if(token != ''){
                            methodChannel.invokeMethod('deleteSharedPreferences','token');

                            //prefs.remove('token');
                          }
                          Navigator.of(context).pushNamedAndRemoveUntil( '/', ModalRoute.withName('/'));
                        },
                      ),
                    ),
                  )
                ]
            ),
          )



      ),
    );
  }
}
